#include <all.h>

static ticker_handle_t tic_test;

static uint16_t test_count = 0;
static uint8_t mempool[2048];

static void tic_test_cb(ticker_event_t *e)
{
	gpio_toggle(led_err);
	gpio_toggle(led_pass);
}




void main()
{
	wire_config_t cfg;
	uint8_t add_buffer[130];

	init_mempool(mempool, sizeof(mempool));

	system_init();

	for (;;)
	{
		if (btn_available())
		{
			uint32_t time = sys_get_time_ms();
			float sec;
			btn_read_event(NULL, NULL);

			gpio_write(led_err, 1);
			gpio_write(led_pass, 0);

			tic_test = ticker_attch_ms(100, tic_test_cb, 0, NULL);

			oled_fill_full_screen(0);
			oled_set_position(28, 24);
			oled_draw_str("测试中...", 1);
			oled_push_screen();

			myprintf_attach(uart_putchar);

			myprintf("\n\n\n\nteset result:\n\n");

			QFTEK_ET01_TEST();
			test_count++;
			sec = sys_get_time_ms() - time;
			sec /= 1000;

			myprintf("\ntest count:%hu\tspent time:%2.3fS\n", test_count, sec);

			myprintf_attach(oled_putchar);

			oled_fill_full_screen(0);
			oled_set_position(0, 2);

			myprintf("测试次数:%hu\n\n用时:%2.3fS\n", test_count, sec);
			oled_push_screen();

			ticker_detach(tic_test);

			gpio_write(led_err, 0);
			gpio_write(led_pass, 0);

			power_off_all();
		}

		ticker_task_handler();


		
	}
}
